define(function (require, exports, module) {
    'use strict';
    var base = require('js/utils/model'),
        _ = require('underscore'),
        moment = require('moment'),
        utils = require('js/utils/tools');

    var Preset = base.Model.extend({
        defaults: {
            "device_type": 0,
            "title": '',
            "remark": '',
            "min_version": 0,
            "max_version": null,
            "off_status": '',
            "content": {
                'notify': {
                    '_disable_activate': false,
                    'wake': [{ //触发性
                        'status': 0, //用户状态 0-安装未注册 1-注册未购买 2-长时间未启动
                        'period': 24, //推送周期，hour
                        'weight': 100,
                        'condition': 1, //状态持续时间，单位：小时
                        'title': '',
                        'content': '',
                        'command': ''
                    }],
                    'activate': [{ //周期性通知
                        'type': 0, //预留
                        'period': 24, //推送周期，hour
                        'time': '22:00', //推送时间点
                        'start_date': '2015-12-08',
                        'end_date': '2015-12-10',
                        'optional': [{
                            'title': '',
                            'content': '',
                            'command': ''
                        }],
                    }]
                },
                'scrolling': {
                    'stay': 5,
                    'fetch_interval': 600
                },
                'ipay': {
                    "webmode": 0,
                },
            }
        },
        urlRoot: "/admin/preset/",
        parse: function (response) {
            if (response.data && response.data.content) {
                if (!response.data.content.scrolling) {
                    response.data.content.scrolling =
                        this.defaults.content.scrolling;
                }
                return response.data;
            }
            return response;
        }
    });
    var PresetCollection = base.Collection.extend({
        model: Preset,
        url: "/admin/preset/",
        total: 0,
        parse: function (response) {
            this.total = response.data.total_count;
            _.each(response.data.list, function (data) {
                data.device_type = utils.getDeviceTypeStr(data.device_type);
            });
            return response.data.list;
        }
    });
    var Reward = base.Model.extend({
        defaults: {
            'title': '',
            'activity_type': 0,
            'bet_type': 0,
            'rate': 0,
            'amount': 0,
            'condition': '',
            'remark': ''

        },
        urlRoot: '/admin/preset/reward/',

    });
    var RewardCollection = base.Collection.extend({
        model: Reward,
        url: "/admin/preset/reward/"
    });
    var Shortcut = base.Model.extend({
        defaults: {
            "title": "",
            "image": "",
            "cmd": ""
        },
        urlRoot: "/admin/preset/shortcut/",
    });
    var ShortcutCollection = base.Collection.extend({
        model: Shortcut,
        url: "/admin/preset/shortcut/",
    });
    var Banner = base.Model.extend({
        defaults: {
            "title": "",
            "abtest": -1,
            "type": "",
            "start_ts": moment().unix() + 1000,
            "end_ts": moment().unix() + 1000,
            "campaign_start": moment().unix() + 1000,
            "campaign_end": moment().unix() + 1000,
            "image": "",
            "cmd": ""
        },
        urlRoot: "/admin/preset/banner/",
    });
    var BannerCollection = base.Collection.extend({
        model: Banner,
        url: "/admin/preset/banner/",
    });
    var Lottery = base.Model.extend({
        defaults: {
            'start_ts': moment().unix() + 1000,
            'end_ts': moment().unix() + 1000,
            'image': '',
            'remark': '',
            'exclude_chn': '',
            'bet_type': 0,
            'tab': 0,
            'cmd': "",
            'start_stop_lottery':null,
            'end_stop_lottery':null
        },
        urlRoot: "/admin/preset/lottery/"
    });
    var LotteryCollection = base.Collection.extend({
        model: Lottery,
        url: "/admin/preset/lottery/",
    });
    var Tab = base.Model.extend({
        defaults: {
            'name': ""
        },
        urlRoot: "/admin/preset/tab/"
    });
    var TabCollection = base.Collection.extend({
        model: Tab,
        url: '/admin/preset/tab/',
    });
    var Discovery = base.Model.extend({
        defaults: {
            "start_ts": moment().unix() + 1000,
            "end_ts": moment().unix() + 1000,
            "title": "",
            "desc": "",
            "tag": "",
            "icon": "",
            "cmd": "",
            "abtest": -1
        },
        urlRoot: "/admin/preset/discovery/",
    });
    var DiscoveryCollection = base.Collection.extend({
        model: Discovery,
        url: "/admin/preset/discovery/",
    });

    var Loading = base.Model.extend({
        defaults: {
            "start_date": '',
            "end_date": '',
            "title": "",
            "desc": "",
            "imageUrl": "",
            "command": "",
            "abtest": -1
        },
        urlRoot: "/admin/preset/loading/",
    });
    var LoadingCollection = base.Collection.extend({
        model: Loading,
        url: "/admin/preset/loading/",
    });

    var Pay = base.Model.extend({
        defaults: {
            "title": "",
            "icon": "",
            "least_pay": "",
            "pay_type": "",
            "desc_short": "",
            "desc_long": "",
            "hightlight": false,
            "remark": "",
            "weixin_pub_appid": "",
            "weixin_pub_name": "",
            "weixin_pub_qr": ""
        },
        urlRoot: "/admin/preset/pay/",
    });
    var PayCollection = base.Collection.extend({
        model: Pay,
        url: "/admin/preset/pay/",
    });
    var Recommend = base.Model.extend({
        defaults: {
            "title": "",
            "abtest": -1,
            "activity_type": 1,
            "numbers": 0,
            "start_ts": moment().unix() + 1000,
            "end_ts": moment().unix() + 1000,
        },
        urlRoot: "/admin/preset/recommend/",
    });
    var RecommendCollection = base.Collection.extend({
        model: Recommend,
        url: "/admin/preset/recommend/",
    });
    var FloatIcon = base.Model.extend({
        defaults: {
            'title': '',
            'abtest': -1,
            'icon': '',
            'cmd': '',
            'start_ts': moment().unix() + 1000,
            'end_ts': moment().unix() + 1000,
            'remark': ''
        },
        urlRoot: "/admin/preset/float_icon/",
    });
    var FloatIconCollection = base.Collection.extend({
        model: FloatIcon,
        url: '/admin/preset/float_icon/'
    });
    module.exports = {
        Preset: Preset,
        PresetCollection: PresetCollection,
        Shortcut: Shortcut,
        ShortcutCollection: ShortcutCollection,
        Banner: Banner,
        BannerCollection: BannerCollection,
        Discovery: Discovery,
        DiscoveryCollection: DiscoveryCollection,
        Loading: Loading,
        LoadingCollection: LoadingCollection,
        Pay: Pay,
        PayCollection: PayCollection,
        Reward: Reward,
        RewardCollection: RewardCollection,
        Recommend: Recommend,
        RecommendCollection: RecommendCollection,
        FloatIcon: FloatIcon,
        FloatIconCollection: FloatIconCollection,
        Lottery: Lottery,
        LotteryCollection: LotteryCollection,
        Tab: Tab,
        TabCollection: TabCollection
    }
});
